# 赋值运算
l1 = [1, 2, 3, [22, 33]]
l2 = l1
l1.append(666)
print(l1)  # [1, 2, 3, [22, 33], 666]
print(l2)  # [1, 2, 3, [22, 33], 666]

# 浅copy
l1 = [1, 2, 3, [22, 33]]
l2 = l1.copy()
print(id(l1))  # 854728749696
print(id(l2))  # 854728769600
l1.append(666)
print(id(l1))  # 854728749696
print(id(l2))  # 854728769600

l1 = [1, 2, 3, [22, 33]]
l2 = l1.copy()
l1[-1].append(666)
print(id(l1[-1]))  # 27172683008
print(id(l2[-1]))  # 27172683008
print(id(l1[0]))  # 27161618736
print(id(l2[0]))  # 27161618736
print(l1)  # [1, 2, 3, [22, 33, 666]]
print(l2)  # [1, 2, 3, [22, 33, 666]]

l1 = [1, 2, 3, [22, 33]]
l2 = l1.copy()
l1[0] = 90
print(l1)  # [90, 2, 3, [22, 33]]
print(l2)  # [1, 2, 3, [22, 33]]

# 深copy
import copy

l1 = [1, 2, 3, [22, 33]]
l2 = copy.deepcopy(l1)
print(id(l1))  # 160384666432
print(id(l2))  # 160384370240
l1[-1].append(666)
print(l1)  # [1, 2, 3, [22, 33, 666]]
print(l2)  # [1, 2, 3, [22, 33]]

# 相关面试题
# list切片是浅copy
l1 = [1, 2, 3, [22, 33]]
l2 = l1[:]
l1[-1].append(666)
print(l1)  # [1, 2, 3, [22, 33, 666]]
print(l2)  # [1, 2, 3, [22, 33, 666]]

# 浅copy：list dict：嵌套的可变的数据类型是同一个
# 深copy：list dict：嵌套的可变的数据类型不是同一个
